package com.hhss.qishi.mapper.system.provider;

import com.hhss.qishi.entity.Annex;
import org.apache.ibatis.jdbc.SQL;
import org.springframework.util.StringUtils;

/**
 * 附件sql生成器
 * @Author :Administrator
 * @Description
 * @Date :2019-06-04 15:20.
 */
public class AnnexProvider {

	private static String SQL_ENTITY = "id, uuid,"
			+ " fk_uuid AN fkUuid, module, file_name AS fileName, real_name AS realName, file_size AS fileSize,"
			+ " file_suffix AS fileSuffix, directory, virtual_directory AS virtualDirectory, remark,"
			+ " status, create_user AS createUser, create_time AS createTime, last_update_user AS lastUpdateUser,"
			+ " last_update_time AS lastUpdateTime, create_user AS createUser, last_update_user AS lastUpdateUser";

	private static String TABLE_NAME = "sys_annex";

	/**
	 * 查找附件集合
	 * @param annex
	 * @return
	 */
	public String getListSQL(final Annex annex) {
		return new SQL(){{
			SELECT(SQL_ENTITY);
			FROM(TABLE_NAME);
			WHERE("1=1");
			if(!StringUtils.isEmpty(annex.getFileName())) {
				AND().WHERE("file_name like CONCAT('%',#{annex.fileName},'%')");
			}
			if(!StringUtils.isEmpty(annex.getFkUuid())) {
				AND().WHERE("fk_uuid = #{annex.fkUuid}");
			}
			if(!StringUtils.isEmpty(annex.getModule())) {
				AND().WHERE("module = #{annex.module}");
			}
		}}.toString();
	}
}
